################################################################################
#                                                                              #
#        Replication script for analysis contained in:                         #
#        Outdated and Unconstitutional: Rethinking Duration                    #
#        of Residency Requirements for Jury Service,                           #
#        By Barry C. Edwards, J.D., Ph.D.                                      #
#                                                                              #
#        Forthcoming in Creighton Law Review                                   #
#        Expected: Spring 2026                                                 #
#                                                                              #
################################################################################


################## Set-up machine and load datasets ############################
rm(list=ls())      # start with clean environment

# CHANGE THE NEXT LINE to the location of files on your machine
setwd("C:/Users/Barry Edwards/Dropbox/jury research/New Resident Exclusion Article")

# This replication code requires the RCPA3 package.
# The next line installs it if you don't have it already.
if(require("RCPA3", quietly = TRUE)==FALSE) install.packages("RCPA3")
# and then load the RCPA3 package in session.
# The 2020 ANES is in the RCPA3 package already.
library(RCPA3)

nes.comparisons.summary <- getC(file = "Summary of NES Differences.csv", confirm = F)
anes_1958 <- getC("NES1958.POR", confirm=F)
anes_1994 <- getC("NES1994.POR", confirm=F)

# Identify new residents with variable newcommunity (1=yes, 0=no)
# nes$community.yrs records how long respondent have lived in their community
# wt is variable provided with ANES to weight observations for analysis
# sanity checks: freqC(nes$community.yrs, nes$wt), freqC(nes$newcommunity, nes$wt)
nes$newcommunity <- (nes$community.yrs=="0")
  

# III. THE EXCLUSION IS NOT NARROWLY TAILORED TO SERVE COMPELLING STATE INTERESTS
#   A. THE “UNFAMILIAR WITH COMMUNITY” RATIONALE IS NOT SUPPORTED BY ANY EVIDENCE
  
  # No statistically significant difference: understanding of politics (self described)
  crosstabC(dv=nes$pol.understand, iv=nes$newcommunity, w=nes$wt, chisq=T, plot=F, compact = T)
  
  # No statistically significant difference: political knowledge
  nes$polquiz.index <- ((nes$polquiz.fedspend=="1. Foreign aid (correct)") +
                          (nes$polquiz.german=="1. Correct") + 
                          (nes$polquiz.housemaj=="1. Democrats (correct)") +
                          (nes$polquiz.russian=="1. Correct") +
                          (nes$polquiz.scotus=="2. Correct" | nes$polquiz.scotus=="1. Partially correct") +
                          (nes$polquiz.sen.term==6) +
                          (nes$polquiz.senatemaj=="2. Republicans (correct)") +
                          (nes$polquiz.speaker=="1. Correct") +
                          (nes$polquiz.vp=="1. Correct"))
  # sanity check: describeC(nes$polquiz.index)
  # Readable labels for FALSE/TRUE values
  ivlabels <- c("Established Residents", "New Residents")
  
  compmeansC(dv=nes$polquiz.index, iv=nes$newcommunity, ivlabs = ivlabels, 
             w=nes$wt, anova=T, plot=F, compact = T)
  
  # No statistically significant difference: attending meetings about community issues 
  crosstabC(dv=nes$civ12.meeting, iv=nes$newcommunity, ivlabs = ivlabels, 
            w=nes$wt, chisq=T, plot=F, compact = T)
  
  # No statistically significant difference: contacting a state or local government official, 
  crosstabC(dv=nes$civ12.stateoff, iv=nes$newcommunity, ivlabs = ivlabels, 
            w=nes$wt, chisq=T, plot=F, compact = T)
  crosstabC(dv=nes$civ12.statepol, iv=nes$newcommunity, ivlabs = ivlabels, 
            w=nes$wt, chisq=T, plot=F, compact = T)
  
  # No statistically significant difference: turning out to vote 
  crosstabC(dv=nes$turnout2020, iv=nes$newcommunity, ivlabs = ivlabels, 
            w=nes$wt, chisq=T, plot=F, compact = T)
  
  # No statistically significant difference: going to political meetings. 
  crosstabC(dv=nes$polact.meetings, iv=nes$newcommunity, ivlabs = ivlabels, 
            w=nes$wt, chisq=T, plot=F, compact = T)
  
  # No statistically significant difference: attending religious services
  crosstabC(dv=nes$relig.how.often, iv=nes$newcommunity, ivlabs = ivlabels, 
            w=nes$wt, chisq=T, plot=F, compact = T)
  
  # Established residents do pay more attention to politics
  crosstabC(dv=nes$politics.attention, iv=nes$newcommunity, ivlabs = ivlabels, 
            w=nes$wt, chisq=T, plot=F, compact = T)
  
  # New residents are more likely to join a march or demonstration 
  crosstabC(dv=nes$civ12.march, iv=nes$newcommunity, ivlabs = ivlabels, 
            w=nes$wt, chisq=T, plot=F, compact = T)
  
  # New residents are more likely to do volunteer work
  crosstabC(dv=nes$civ12.vol, iv=nes$newcommunity, ivlabs = ivlabels, 
            w=nes$wt, chisq=T, plot=F, compact = T)
  
  # Earlier iterations of the ANES show new residents less likely to identify members of Congress
  # In the 1958 ANES, 33% of newcomers correctly identified at least one candidate 
  # compared to 49% of those with a year or more of residency. 
  # 1958 ANES, 
  # ==============================                                                
  #   VAR 580229    LENGTH CURRENT RESIDENCE   00. UNDER SIX MONTHS (AS OF ELECTION, NOV. 4, 1958)      
  #                                            01. SIX MONTHS TO (BUT NOT INCLUDING) ONE YEAR  
  # VAR 580095    XRECALL DSTRT CNGSL CAND  
  # V580003 WEIGHT FIELD
  crosstabC(dv=anes_1958$V580096>1, iv=anes_1958$V580229<=1, chisq=T, plot=F, 
            dvlabs = c("Don't Know Candidates", "Know Candidates"),ivlabs = ivlabels,
            w=anes_1958$V580003, digits=1)
  
  
  # In the 1994 ANES, 29% for newcomers and 44% for established residents. 
  # V940210,  1. VALID CANDIDATE NAME GIVEN AND CORRECT PARTY
  # V941423,  HOW LONG IN COMMUNITY 00.  LESS THAN 6 MONTHS, 01.  6-12 MONTHS
  # V940004 is variable for weighting observations
  anes_1994$newcomer <- as.numeric(anes_1994$V941423<2)
  # sanity check: freqC(anes_1994$newcomer)  
  crosstabC(dv=as.factor(anes_1994$V940210), iv=anes_1994$newcomer, w=anes_1994$V940004,
            ivlabs = ivlabels, dvlabs = c("Know Candidates", "Don't Know Candidates"),
            digits = 1, plot=F) # iv=anes_1994$newcomer)


# III. THE EXCLUSION IS NOT NARROWLY TAILORED TO SERVE COMPELLING STATE INTERESTS
#  C.	 NEW RESIDENTS ARE DISTINCTIVE GROUP BASED ON OTHER CRITERIA
#  4.	 New Residents Have Distinct Viewpoints, Opinions, and Attitudes

  # New residents gave significantly different answers on 311 of the questions (73.5% of items).
  freqC(x = (nes.comparisons.summary$p.value <= .05), digits=1, plot=F,
        rowlabs = c("Not Significantly Different", "Significantly Different"))
  
  # Table 3: Distinctive Opinions and Characteristics of New Residents
  crosstabC(dv=nes$feminist, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
            w=nes$wt, chisq = T, plot=F, compact = T)
  compmeansC(dv=nes$ft.transgender, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
             w=nes$wt, anova=T, plot=F, compact = T)
  crosstabC(dv=nes$trans.military, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
            w=nes$wt, chisq = T, plot=F, compact = T)
  crosstabC(dv=nes$fedspend.crime, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
            w=nes$wt, chisq = T, plot=F, compact = T)
  compmeansC(dv=nes$ft.police, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
             w=nes$wt, anova=T, plot=F, compact = T)
  crosstabC(dv=nes$fedspend.border, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
            w=nes$wt, chisq = T, plot=F, compact = T)
  compmeansC(dv=nes$ft.gays.lesbians, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
             w=nes$wt, anova=T, plot=F, compact = T)
  compmeansC(dv=nes$ft.muslims, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
             w=nes$wt, anova=T, plot=F, compact = T)
  crosstabC(dv=nes$marital, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
            w=nes$wt, chisq = T, plot=F, compact = T)
  crosstabC(dv=nes$has.nokids, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
            w=nes$wt, chisq = T, plot=F, compact = T)
  crosstabC(dv=nes$hh.landline, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
            w=nes$wt, chisq = T, plot=F, compact = T)
  compmeansC(dv=nes$age, iv=nes$newcommunity, ivlabs = ivlabels, digits = 1, 
             w=nes$wt, anova=T, plot=F, compact = T)
  
  

  

